package com.baichang.taoshunda.controller.mobile;

import com.baichang.framework.controller.BaseMobileController;
import com.baichang.framework.controller.IService;
import com.baichang.framework.excelption.ServiceException;
import com.baichang.taoshunda.controller.ControllerConstants;
import com.baichang.taoshunda.service.WaiterService;
import com.baichang.taoshunda.service.WaiterTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by ${wushenglu} on 2017/8/18 0018.
 */
@Controller
@RequestMapping(ControllerConstants.LOCAL)
public class LocalServiceMCtronller extends BaseMobileController {
    @Autowired
    private WaiterTypeService waiterTypeService;
    @Autowired
    private WaiterService waiterService;

    /**
     * 获取本地服务的类型
     *
     * @param request
     * @param response
     */
    @RequestMapping("/getwaiterType")
    public void getwaiterType(HttpServletRequest request, HttpServletResponse response) {
        initEncode(request, response, new IService() {
            @Override
            public Object init(HttpServletRequest request, HttpServletResponse response, String json) throws ServiceException {
                int isHome = getInt(json, "isHome", 1);
                return waiterTypeService.getwaiterType(isHome);
            }
        });
    }

    /**
     * 获取本地服务列表
     *
     * @param request
     * @param response
     */
    @RequestMapping("/getwaiterList")
    public void getwaiterList(HttpServletRequest request, HttpServletResponse response) {
        initEncode(request, response, new IService() {
            @Override
            public Object init(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, String s) throws ServiceException {
                int typeId = getInt(s, "typeId", 0);
                int cityId = getInt(s, "cityId", 4);
                int userId = getInt(s, "userId", 4);
                int areaId = getInt(s, "areaId", 0);
                double ulng = getDouble(s, "ulng", 0);
                double ulat = getDouble(s, "ulat", 0);
                int nowPage = getInt(s, "nowPage", 1);
                int pageSize = getInt(s, "pageSize", 20);
                return waiterService.getwaiterList(typeId, cityId, ulat, ulng, nowPage, pageSize, userId, areaId);
            }
        });
    }

    /**
     * 服务商家详情
     *
     * @param request
     * @param response
     */
    @RequestMapping("/getWaiterDetail")
    public void getWaiterDetail(HttpServletRequest request, HttpServletResponse response) {
        initEncode(request, response, new IService() {
            @Override
            public Object init(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, String s) throws ServiceException {
                Integer id = getInt(s, "id", 0);
                int userId = getInt(s, "userId", 0);
                return waiterService.getWaiterDetail(id, userId);
            }
        });
    }
}
